<template>
	<div>



		<form>

			<el-row>
				<el-col :span="10">

					<el-input v-model="query.realname" placeholder="请输入查询的用户姓名"></el-input>
				</el-col>

				<el-col :span="4">

					<el-button type="primary" @click="list">查询</el-button>
					<el-button type="primary" @click="add">添加</el-button>

				</el-col>
			</el-row>
		</form>

		<el-table :data="tableData" size="mini"  style="width: 100%">


			<el-table-column label="id" width="40" prop="userId">
			</el-table-column>
			<el-table-column label="用户名" prop="username">
			</el-table-column>

			<el-table-column label="医生姓名" prop="realname">
			</el-table-column>

			<el-table-column label="电话号" prop="telephone">
			</el-table-column>


		<!-- 	<el-table-column label="归属部门" prop="deptId">
			</el-table-column> -->


			<el-table-column label="最后一次登录时间" prop="lastlogin">
			</el-table-column>
			
			<el-table-column label="关联角色">
				<template slot-scope="scope">
					<el-button size="mini" @click="userRole(scope.row.userId)">关联角色</el-button>
					
				</template>
			</el-table-column>
			
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="mini" @click="edit(scope.row.userId)">编辑</el-button>
					<el-button size="mini" type="danger" @click="del(scope.row.userId)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>


		<el-pagination background layout="prev, pager, next" @current-change="currentChange" :current-page.sync="query.pageNo"
		 :page-size="pageSize" :total="total">
		</el-pagination>

		<el-dialog title="用户编辑" :visible.sync="showEdit">

			<UserEdit :showEdit.sync="showEdit" @update="list" :userId="userId" :key="showNum"></UserEdit>

		</el-dialog>
		
		
		
		<el-dialog title="用户角色" :visible.sync="showUserRole">
		
			<UserRole :showUserRole.sync="showUserRole"  :userId="userId" :key="showNum"></UserRole>
		
		</el-dialog>

	</div>
</template>

<script>
	import UserEdit from '@/views/user/edit'
	import UserRole from '@/views/user/user_role'
	export default {
		name: 'User',
		components: {
			UserEdit,UserRole
		},
		data() {
			return {
				showNum: 0,
				pageSize: 10,
				total: 0,
				userId: null,
				showEdit: false,
				showUserRole: false,
				query: {
					pageNo: 1,
					realname: ''
				},
				tableData: []
			}
		},
		methods: {
			list() {
			
				this.axios.get('/user?type=query',(data)=>{
					this.tableData = data.list;
					this.pageSize = data.pageSize;
					this.total = data.totalCount;
				},this.query);
			},
			add() {
				this.showNum++;
				this.showEdit = true;
			},
			edit(id) {
				this.userId = id;
				this.showNum++;
				this.showEdit = true;
			},
			del(id){
				this.axios.get('/user?type=del',(data)=>{
					if(data){
						this.$alert("删除成功","提示",{
							type:'success'
						});
						//刷新页面
						this.list();
					}
				},{
					userId:id
				});
			},
			currentChange() {
				this.list();
			},
			//用户关联角色
			userRole(userId){
				this.showNum++;
				this.userId = userId;
				
				this.showUserRole = true;
			}

		},
		created() {

			this.list();
		}
	}
</script>

<style>
</style>
